package com.jadesoft.stock.util;

import org.apache.log4j.Logger;

import com.ufida.commons.IPublished;
import com.ufida.leaf.persistence.PlatformTransactionManager.TransManager;
import com.ufida.leaf.persistence.PersistenceImp;

/**
 * @author UFIDA POC Team
 *
 */
public aspect TransactionAspect implements IPublished {

	private static final Logger logger = Logger.getLogger(TransactionAspect.class);

	Object around():businessTransaction()||persistenceTransaction(){
		TransManager tm = new TransManager();
		
		try {
			tm.begin();
			Object result = proceed();
			tm.commit();
			return result;
		} catch (RuntimeException e) {
			tm.rollback();
			logger.error("TransactionAspect Rollback:"+e.getMessage());
			throw e;
//			if (logger.isDebugEnabled()) {
//				e.printStackTrace();
//			}
//			String msg = e.getMessage();
//			if (StringUtils.isBlank(msg)) {
//				msg = "��ݿ�����?�����Ѿ��ع�";
//			}
//			throw new BusinessException(msg, e);
		}
		catch (Error e) {
			tm.rollback();
			throw e;
		}
	}

	pointcut businessTransaction():execution(* *TA(..));

	pointcut persistenceTransaction():within(PersistenceImp)&&
	(execution(* saveObjs*(..))||execution(* updateObjs*(..))
			||execution(* delete*(..))||execution(* executeUpdateWith*(..)));

}
